using Domain.Dto;
using Gmmy.DomainExtension;
using System;
using System.Linq.Expressions;

namespace Domain.Specification
{
    public class RoleListSpecification : Specification<RoleListInput>
    {
        public string RoleName { get; set; }
        public string Remark { get; set; }
        public int? Sort { get; set; }


        public RoleListSpecification(RoleListInput input)
        {
            RoleName = input.RoleName;
            Remark = input.Remark;
            Sort = input.Sort;

        }

		/// <summary>
        /// 查询规约
        /// </summary>
        /// <returns></returns>
        public override Expression<Func<RoleListInput, bool>> SatisfiedBy()
        {
            var where = PredicateBuilder.True<RoleListInput>().And(x => !x.IsDeleted);
            if (!string.IsNullOrEmpty(RoleName))
            {
                where = where.And(x => x.RoleName.Contains(RoleName));
            }
            if (!string.IsNullOrEmpty(Remark))
            {
                where = where.And(x => x.Remark.Contains(Remark));
            }
            if (Sort != null)
            {
                where = where.And(x => x.Sort == Sort);
            }

            return where;
        }
    }
}
